// AutoCADMenu.h: interface for the AutoCADMenu class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_AUTOCADMENU_H__ACCE70E1_08BE_4EFC_A43C_2DA850C69268__INCLUDED_)
#define AFX_AUTOCADMENU_H__ACCE70E1_08BE_4EFC_A43C_2DA850C69268__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <vector>
using namespace std;

namespace UEPHSMENU
{
	class MenuGroup;
	class PopMenu;
	class MenuItem;

	class DllExport AutoCADMenu
	{
	private:
		typedef vector<MenuGroup*> Groups_;
	public:
		typedef Groups_::iterator Iterator;
	public:
		AutoCADMenu();
		virtual ~AutoCADMenu();
	public:
		void AddMenuGroup(MenuGroup *pMGroup);
		Iterator MenuGroupIterator(){
			return m_Groups.begin();
		}

		Iterator End(){
			return m_Groups.end();
		}
		MenuGroup * Find(const CString& strGroupName);
	private:
		Groups_ m_Groups;
	};


	class DllExport MenuGroup
	{
	private:
		typedef vector<PopMenu*> Groups_;
	public:
		typedef Groups_::iterator Iterator;
	public:
		MenuGroup();
		virtual ~MenuGroup();
	public:
		void AddPopMenu(PopMenu *pPopMenu);
		void Name(const CString& strName){
			ASSERT(!strName.IsEmpty());
			m_strGroupName = strName;
		}
		const CString& Name()const{
			return m_strGroupName;
		}
		void MenuName(const CString& strMenuName){
			ASSERT(!strMenuName.IsEmpty());
			m_strMenuName = strMenuName;
		}
		const CString& MenuName()const{
			return m_strMenuName;
		}
		Iterator PopMenuIterator(){
			return m_Groups.begin();
		}
		Iterator End(){
			return m_Groups.end();
		}
		PopMenu * Find(const CString& strMenuID);
	private:
		CString m_strGroupName;
		CString m_strMenuName;
		Groups_ m_Groups;
	};

	class DllExport PopMenu
	{
	private:
		typedef vector<MenuItem*> Groups_;
	public:
		typedef Groups_::iterator Iterator;
	public:
		PopMenu();
		virtual ~PopMenu();
	public:
		void AddMenuItem(MenuItem *pMItem);
		void PopN(int nPop){
			m_nPopN = nPop;
		}
		int PopN()const{
			return m_nPopN;
		}
		void MenuID(const CString& strMenuID){
			ASSERT(!strMenuID.IsEmpty());
			m_strMenuID = strMenuID;
		}
		const CString& MenuID() const{
			return m_strMenuID;
		}
		void Title(const CString& strTitle){
			ASSERT(!strTitle.IsEmpty());
			m_strTitle = strTitle;
		}
		const CString& Title(){
			return m_strTitle;
		}
		Iterator MenuItemIterator(){
			return m_Groups.begin();
		}
		Iterator End(){
			return m_Groups.end();
		}
	private:
		int m_nPopN;
		CString m_strMenuID;
		CString m_strTitle;
		Groups_ m_Groups;
	};

	class DllExport MenuItem
	{
	private:
		typedef vector<MenuItem*> Groups_;
	public:
		typedef Groups_::iterator Iterator;
	public:
		MenuItem();
		virtual ~MenuItem();
	public:
		void AddMenuItem(MenuItem *pMItem);
		void Name(const CString& strName){
			ASSERT(!strName.IsEmpty());
			m_strName = strName;
		}
		const CString& Name() const{
			return m_strName;
		}
		void Cmd(const CString& strCmd){
		//	ASSERT(!strCmd.IsEmpty());
			m_strCommand = strCmd;
		}
		const CString& Cmd(){
			return m_strCommand;
		}
		Iterator MenuItemIterator(){
			return m_Groups.begin();
		}
		Iterator End(){
			return m_Groups.end();
		}
		BOOL IsSubMenu(){
			return m_Groups.begin() == NULL? FALSE:TRUE;
		}
	private:
		CString m_strName;
		CString m_strCommand;
		Groups_ m_Groups;
	};

	class DllExport AutoCADMenuReader
	{
	public:
		AutoCADMenuReader(const CString strMenuFile);
		virtual ~AutoCADMenuReader();
	public:
		AutoCADMenu * Reader();
	private:
		static BOOL IsComment(const CString& strValue){
			return strValue.Left(2) == "//" ? TRUE:FALSE;
		}
		static void Trim(CString& strValue){
			strValue.TrimLeft();
			strValue.TrimRight();
		}
		void ReadMenuFile();
		void ParseCmdName(const CString& strValue,CString& strName,CString& strCmd);
		BOOL ReadMenuGroup(AutoCADMenu *pCADMenu);
		BOOL ReadPopMenu(int& nIndex,MenuGroup *pMGroup);
		BOOL ReadMenuItem(int& nIndex,PopMenu *pPopMenu);
		BOOL ReadMenuItem(int& nIndex,MenuItem *pMItem);
	private:
		CString m_strMenuFile;
		CStringArray m_Array;
	};

	class DllExport AutoCADMenuWriter
	{
	public:
		AutoCADMenuWriter(const CString strMenuFile);
		virtual ~AutoCADMenuWriter();
	public:
		BOOL Writer(AutoCADMenu * pCADMenu);
	private:
		BOOL WriteMenuGroup(CStdioFile & file,MenuGroup* pMGroup);
		BOOL WritePopMenu(CStdioFile & file,PopMenu* pPMenu);
		BOOL WriteMenuItem(CStdioFile & file,MenuItem* pMItem);
	private:
		CString m_strMenuFile;
	};

}
#endif // !defined(AFX_AUTOCADMENU_H__ACCE70E1_08BE_4EFC_A43C_2DA850C69268__INCLUDED_)
